package com.googlecode.microanalyst.palette.edit;

import org.eclipse.gef.EditPart;
import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;

import com.googlecode.microanalyst.designer.edit.AnalysisElementEditPolicy;
import com.googlecode.microanalyst.designer.edit.NativeDropRequest;
import com.googlecode.microanalyst.palette.model.LabeledConnection;
import com.googlecode.microanalyst.palette.model.cmd.LabeledConnectionLabelCommand;

public class LabeledConnectionEditPolicy extends AnalysisElementEditPolicy {

	public Command getCommand(Request request) {
		if (NativeDropRequest.ID.equals(request.getType()))
			return getDropTextCommand((NativeDropRequest) request);
		return super.getCommand(request);
	}

	protected Command getDropTextCommand(NativeDropRequest request) {
		LabeledConnectionLabelCommand command = new LabeledConnectionLabelCommand((LabeledConnection) getHost()
				.getModel(), (String) request.getData());
		return command;
	}

	public EditPart getTargetEditPart(Request request) {
		if (NativeDropRequest.ID.equals(request.getType()))
			return getHost();
		return super.getTargetEditPart(request);
	}

}
